/**数据验证*/
var HrUserValidator = function() {  
    var handleSubmit = function() { 
        $('.form-horizontal').validate({  
            errorElement : 'span',  
            errorClass : 'help-block',  
            focusInvalid : false,  
            rules : {  
            	"name" : {  
                    required : true  
                },
                "icard" : {  
                    required : true  
                },
                "tel" : {  
                    required : true  
                },
                "workmoney" : {  
                    number : true  
                }
            },  
            messages : {  
            	"name" : {  
                    required : "请输入姓名."
                },
                "icard" : {  
                    required : "请输入身份证号."
                },
                "tel" : {  
                    required : "请输入联系电话."
                },
                "workmoney" : {  
                    number : "请输入数字"
                }
            },  
  
            highlight : function(element) { 
                $(element).closest('.control-group').addClass('error');  
            },  
  
            success : function(label) { 
                label.closest('.control-group').removeClass('error');  
                label.remove();
            },  
  
            errorPlacement : function(error, element) {  
            	element.parent('div').append(error);  
            },  
  
            submitHandler : function(form) {
                form.submit();
            }  
        });  
  
        $('.form-horizontal input').keypress(function(e) {  
            if (e.which == 13) {  
                if ($('.form-horizontal').validate().form()) {  
                    $('.form-horizontal').submit();  
                }  
                return false;  
            }  
        });  
    }  
    return {  
        init : function() { 
            handleSubmit(); 
        }  
    };  
  
}(); 


/**保存数据*/
function saveHrUser(){
	$('#myModal').modal('show');
	//住户信息
	var puid=$("#puid").val();
	var name=$("#name").val();
	var state=$("input[type=radio][name=state]:checked").val();
	var birthday=$("#birthday").val();
	
	var sex=$("input[type=radio][name=sex]:checked").val();
	var icard=$("#icard").val();
	var did=$("#did").val();
	var wid=$("#wid").val();
	var wcid=$("#wcid").val();
	var workmoney=$("#workmoney").val();
	var sid=$("#sid").val();
	var ctime=$("#ctime").val();
	var wtid=$("#wtid").val();
	
	var addr=$("#addr").val();
	var tel=$("#tel").val();
	var ltime=$("#ltime").val();
	var content=$("#hrcontent").val();
	
	$.post("../hr/save_HrUser.action",{"hrUser.puid":puid,"hrUser.name":name,"hrUser.state":state,
		"hrUser.birthday":birthday,"hrUser.sex":sex,"hrUser.icard":icard,"hrUser.dept.did":did,
		"hrUser.work.wid":wid,"hrUser.workContent.wcid":wcid,"hrUser.workmoney":workmoney,
		"hrUser.school.sid":sid,"hrUser.ctime":ctime,"hrUser.workType.wtid":wtid,
		"hrUser.addr":addr,"hrUser.tel":tel,"hrUser.ltime":ltime,"hrUser.content":content
		}, function(result) {
		if(result.msg=="succ"){
			$('#myModal').modal('hide');
			$("#alertinfo").html("人事信息维护成功");
			$('#myinfo').modal('show');
			$("#closewin").bind("click",function(){
				window.location.href="../hr/queryPage_HrUser.action";
			});
		}else{
			$('#myModal').modal('hide');
			$("#alertinfo").html(result.msg);
			$('#myinfo').modal('show');
		}
	});
};


$(document).ready(function(){
	HrUserValidator.init();
});
